#include<iostream>
using namespace std;

typedef long long ll;
const ll N = 1e5 + 10;
ll arr[N];

int main()
{
    ll n; cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    ll q; cin >> q;
    ll x, y; ll l, r;
    while (q--)
    {
        cin >> x >> y;
        ll left = 0; ll right = n - 1;
        if (arr[0] > y || arr[right] < x)
        {
            cout << 0 << endl;
            continue;
        }

        while (left < right)
        {
            ll mid = left + (right - left) / 2;

            if (arr[mid] >= x)
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        l = left;

        left = 0; right = n - 1;
        while (left < right)
        {
            ll mid = left + (right - left + 1) / 2;

            if (arr[mid] <= y)
            {
                left = mid;
            }
            else
            {
                right = mid - 1;
            }
        }
        r = right;
        cout << r - l + 1 << endl;
    }

    return 0;
}